/**
  **************************************************************************
  * @file    config-util.h
  * @author  huhao
  * @version V1.0.0
  * @date    10-20-2020
  * @brief   读取配置文件信息
  * @project linux client
  ***************************************************************************
  * @attention
  *
  * <h2><center>&copy; COPYRIGHT 2020 上海今中网络科技有限公司 </center></h2>
  ***************************************************************************
*/

#ifndef __CONFIG_UTIL__H__
#define __CONFIG_UTIL__H__

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include "stringx.h"

#define IN
#define OUT
#define CONFIG_MAXLEN   1024

#define init_config  CONFIG_UTIL_INIT
#define free_config  CONFIG_UTIL_FREE

typedef struct _config_util_t CONFIG_UTIL_T;

typedef int   read_config_t(IN CONFIG_UTIL_T *configUtil, IN const char *fileName);
typedef int   get_int_t(IN CONFIG_UTIL_T *configUtil, IN const char *field, IN int defaultvalue);
typedef char *get_string_t(IN CONFIG_UTIL_T *configUtil, IN const char *field, IN char *defaultValue);
typedef void  set_int_t(IN CONFIG_UTIL_T *configUtil, IN const char *field, IN int newValue);
typedef void  set_string_t(IN CONFIG_UTIL_T *configUtil, IN const char *field, IN const char *newValue);
typedef void  commit_config_t(IN CONFIG_UTIL_T *configUtil, IN const char *pathName);
typedef void  free_config_t(IN CONFIG_UTIL_T *configUtil);




/**
  * @brief      构造函数,进行面向对象的封装
  * @param      arg1
  * @retval     void
  */
//void CONFIG_UTIL_INIT(IN CONFIG_UTIL_T *configUtil);

/**
  * @brief      析构函数 释放占用的内存(必须调用)
  * @param      arg1、pathName
  * @retval     NULL
  */
//void CONFIG_UTIL_FREE(IN CONFIG_UTIL_T *configUtil);

/**
  * @brief      构造函数,进行面向对象的封装
  * @param      arg1
  * @retval     void
  */
void init_config(IN CONFIG_UTIL_T *configUtil);

/**
  * @brief      读取文件字段
  * @param      arg1、文件名
  * @retval     成功返回0，失败-1
  */
int read_config(IN CONFIG_UTIL_T *configUtil, IN const char *fileName);

/**
  * @brief      获取整型数据
  * @param      arg1、field
  * @retval     成功对应数值，失败defaultvalue
  */
int get_int(IN CONFIG_UTIL_T *configUtil, IN const char *field, IN int defaultvalue);

/**
  * @brief      获取字符串
  * @param      arg1、field
  * @retval     成功对应数值或defaultValue,失败返回NULL
  */
char *get_string(IN CONFIG_UTIL_T *configUtil, IN const char *field, IN char *defaultValue);

/**
  * @brief      设置整型数据
  * @param      arg1、field arg2、newValue
  * @retval     NULL
  */
void set_int(IN CONFIG_UTIL_T *configUtil, IN const char *field, IN int newValue);

/**
  * @brief      设置字符串数据
  * @param      arg1、field arg2、newValue
  * @retval     NULL
  */
void set_string(IN CONFIG_UTIL_T *configUtil, IN const char *field, IN const char *newValue);

/**
  * @brief      保存数据到文件(修改文件数据时需调用)
  * @param      arg1、pathName
  * @retval     NULL
  */
void commit_config(IN CONFIG_UTIL_T *configUtil, IN const char *pathName);

/**
  * @brief      释放占用的内存(必须调用)
  * @param      arg1、pathName
  * @retval     NULL
  */
void free_config(IN CONFIG_UTIL_T *configUtil);



struct _config_util_t
{
    int                  count;
    char               **nameList;
    char               **valueList;

    read_config_t       *readConfig;
    commit_config_t     *commitConfig;
    free_config_t       *freeConfig;
    get_int_t           *getInt;
    get_string_t        *getString;
    set_int_t           *setInt;
    set_string_t        *setString;
};



#endif // __CONFIG__H__

/******************* (C) COPYRIGHT 2020 上海今中网络科技有限公司 *****END OF FILE****/

